﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Reflection;

/// <summary>
/// Summary description for DatabaseManager
/// </summary>
public class DatabaseManager
{
	public static ConnectionsShowcaseDataContext db;
	private static string serial = "Serialized";
	public static void Initialize()
	{
		//
		// TODO: Add constructor logic here
		//
		db = new ConnectionsShowcaseDataContext();
	}

	/// <summary>
	/// Searches through the database and finds relevant projects
	/// </summary>
	/// <param name="query">What you want to search for</param>
	/// <returns>An array of project IDs which are releveant to your query</returns>
	public static string Search(string query)
	{
		//hardcoded bullshit since we don't have stored procedures yet
		// <div> <Img/></div><div><div>Result</div><div>Discription</div></div>
		string[] temp = new string[5];
		temp[0] = Formatter.SearchResult("http://www.floral-directory.com/flower.gif", "Billy", "First Result Billy was an answer");
		temp[1] = Formatter.SearchResult("http://www.shopbakersnook.com/uploaded/images/monogram%20pics%20on%20cakes/Monogram%20cake%20chocolate.jpg", "Bob", "Bob jones like to eat chocolate cake");
		temp[2] = Formatter.SearchResult("http://www.treehugger.com/lawn%20mower.jpg", "Elliot", "Elliott James Babb is Mowing the lawn.");
		temp[3] = Formatter.SearchResult("http://www.code.co.uk/code.jpg", "Austin", "Austin Wrote this code because its hard coded");
		temp[4] = Formatter.SearchResult("http://plus.maths.org/issue23/features/data/data.jpg", "Data", "If we had more data and stored procedures this would actually work.");
		return Serializer(temp);
	}

	public static string GetProjectNews(string projectID)
	{
		string[] temp = new string[5];
		temp[0] = Formatter.News("10/06/2010", "Login available", "beta is ready for people to login and test");
		temp[1] = Formatter.News("05/19/2010", "Double click", "Implemented a new double click feature");
		temp[2] = Formatter.News("02/27/2010", "new update", "We are still on track");
		temp[3] = Formatter.News("02/13/2010", "Added Search", "Implemented search in the project");
		temp[4] = Formatter.News("01/01/2010", "Started Project", "We just started the project");
		return Serializer(temp);
	}

	public static string GetProjectAbout(string projectID)
	{
		string[] temp = new string[1];
		temp[0] = Formatter.About("this project is all about getting money and getting paid");
		return Serializer(temp);
	}

	public static string GetProjectMembers(string projectID)
	{
		string[] temp = new string[5];
		temp[0] = Formatter.Members("http://www.floral-directory.com/flower.gif", "Billy", "hello i go to school");
		temp[1] = Formatter.Members("http://www.shopbakersnook.com/uploaded/images/monogram%20pics%20on%20cakes/Monogram%20cake%20chocolate.jpg", "Bob", "hi i am bob");
		temp[2] = Formatter.Members("http://www.treehugger.com/lawn%20mower.jpg", "Elliot", "Elliott James Babb is Myname.");
		temp[3] = Formatter.Members("http://c1.ac-images.myspacecdn.com/images02/51/m_a9272a0453c14247834faf11f0fd4bf0.jpg", "Austin", "Austin has no friends");
		temp[4] = Formatter.Members("http://plus.maths.org/issue23/features/data/data.jpg", "Data", "If we had more data and stored procedures this would actually work.");
		return Serializer(temp);
	}

	public static string GetProjectCompany(string projectID)
	{
		string[] temp = new string[1];
		temp[0] = Formatter.Company("http://chandrakantha.com/articles/indian_music/filmi_sangeet/media/1998_google2.jpg", "Google", "Founders Larry Page and Sergey Brin named the search engine they built 'Google,' a play on the word 'googol,' the mathematical term for a 1 followed by 100 zeros. The name reflects the immense volume of information that exists, and the scope of Google's mission: to organize the world's information and make it universally accessible and useful.", "http://www.google.com");
		return Serializer(temp);
	}

	public static string GetProjectResources(string projectID)
	{
		return "<li><div>internet</div></li><li><div>google</div></li><li><div>doctor B</div></li>";
	}

    public static string GetProjectBadge(string projectId)
    {
        //  AA Hit the database for the string imageUrl, string projectName, string description, string url
        string imageUrl = "http://www.google.com/images/logos/ps_logo2.png";
        string projectName = "Google";
        string description = "Beginning in 1996, Stanford University graduate students Larry Page and Sergey Brin built a search engine called 'BackRub' that used links to determine the importance of individual web pages. By 1998 they had formalized their work, creating the company you know today as Google.";
        string url = "http://www.Google.com";
        return Formatter.Badge(imageUrl, projectName, description, url);
    }
	private static string Serialize(string nonSerialized)
	{
		return "<div class='"+serial+"'>" + nonSerialized + "</div>";
	}

	private static string Serializer(string[] nonSerialized)
	{
		string temp = "";
		foreach (string s in nonSerialized)
		{
			temp += Serialize(s);
		}
		return temp;
	}


	#region oldshit
	//public static string[] GetProjectNames(string category)
	//{

	//    return null;
	//    //return db.ExecuteCommand(query.ToString(), null);
	//    //db.ExecuteQuery(typeof(string), query.ToString(), null);
	//    //db
	//    //return db.ExecuteQuery(typeof(string), query, null);
	//}

	//public static string Hello()
	//{
	//    return "Bob";
	//}
	//public static string GetProjectHighlights(int projectID)
	//{
	//    return db.projects.Single(p => p.project_ID == projectID).project_description.ToString();
	//}

	//public static string GetProjectImage(int projectID)
	//{
	//    return db.assets.Single(a => a.project_ID == projectID).asset_description.ToString();
	//}

	//public static string GetProjectTitle(int projectID)
	//{
	//    return db.projects.Single(p => p.project_ID == projectID).project_name.ToString();
	//}

	//public static string GetProjectStatus(int projectID)
	//{
	//    //return db.project_status.Single(p => p. == projectID).project_name.ToString();
	//    return null;
	//}
	#endregion


}



